from idlelib.config import IdleConf


class Fib:
    def __init__(self):
        self.__items = [1,1]

    def __repr__(self):
        return str(self.__items)

    def __iadd__(self, other):
        self.__items.append(other)
        return self

    def __getitem__(self, index):
        # length =  len(self)
        if index < 1:
            raise IndexError('index out of bound')
        if index <= len(self):
            return self.__items[index-1]
        else:
            self.__genitems(index - len(self))
            return self.__items[index-1]

    def __genitems(self, times):
        for i in range(times):
            self += self.__items[-1] + self.__items[-2]
            #self.__items.append(self.__items[-1] + self.__items[-2])


    def __iter__(self):
        yield from self.__items

    def __len__(self):
        return len(self.__items)

f = Fib()
print(len(f))
print(f)
print(f[1],f[2],f[3],f[4],f[5],f[10])
print(len(f))
for x in f:
    print(x)
print(f[5])
